using System.Collections.Generic;
using Belmost4PDA.Constants;
using Belmost4PDA.Fasade;

namespace Belmost4PDA.Logic
{
    public class CmdChangeParam:AbstractCommand
    {
        private readonly ParamItem paramItem = null;
        public ControlsBuilder builder = new ControlsBuilder();
        public AbstractCommand loadCommand = null;

        public CmdChangeParam(ParamItem paramItem)
        {
            this.paramItem = paramItem;
            if (paramItem.IsGrid == false)
                loadCommand = new CmdReadData();
            else
                loadCommand = new CmdReadData(true);
        }
        public override void Execute(ref AbstractState currentState, ref AbstractControl TopControl,
                                     ref List<AbstractMapper> AllMappers)
        {
            if(currentState.AskToDo(this))
            {
                currentState = AbstractState.Create(StateID.View);
                currentState.WorkedParam = paramItem;
                builder.Build(null, paramItem);
                TopControl = builder.GetControls();
                AllMappers = builder.GetMappers();
                InterfaceDispatcher.ExecCommand(loadCommand);
                InterfaceDispatcher.SetPanel(paramItem.IDTopPanel);
                InterfaceDispatcher.IDs.Clear();
            }
        }

        public override CommandID GetID()
        {
            return CommandID.ChangeParam;
        }
    }
}
